<!--smt订单-邮寄 smt弹框 -->
<template>
  <el-dialog :visible.sync="smtVisible" width="800px">
    <div>
      <Table
        :data="data.mailingData.bomData"
        :columns="columns"
        serial
        :serialOptions="{
          pageNum: data.mailingData.pageNumber,
          pageSize: data.mailingData.pageSize,
        }"
      >
      </Table>
      <Pagination
        class="m-b-10"
        v-show="data.mailingData.totalRow > 0"
        :total="data.mailingData.totalRow"
        v-model:page="data.mailingData.pageNumber"
        v-model:limit="data.mailingData.pageSize"
        @pagination="handlePaginationPcbChange"
      />
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="goToMail">{{ $t('om.GotoPost') }}</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref, reactive, onMounted, computed } from 'vue';
import Table from '@/components/Table/index.vue';
import Pagination from '@/components/Pagination/index.vue';
import { useRouter } from 'vue-router';
import {
  queryPagePcbaSmtBomOrderExpressList,
  getBomOrderDetail,
  queryPcbaPcbOrderList,
} from '@/server/api/biz.js';
const props = defineProps({
  value: {
    type: Boolean,
    default: false,
  },
  smtInfo: {
    type: Object,
    default: () => {},
  },
});
const router = useRouter();
const emit = defineEmits(['closeSmtWaitingMailingModel', 'goToMail']);
const columns = computed(() => [
  {
    label: t('mall.component_information'),
    prop: 'materialsName',
  },
  {
    label: t('mall.suggested_quantity'),
    width: '200px',
    prop: 'totalQuantity',
  },
]);
const data = reactive({
  mailingData: {
    pageNumber: 1,
    pageSize: 10,
    bomData: [],
    totalRow: 0,
  },
});
const smtVisible = ref(false);

const goToMail = () => {
  router.push({ query: { type: 1, tabs: 1, recordType: 2 } });
  emit('goToMail');
  emit('closeSmtWaitingMailingModel');
};

/**
 * 获取bom邮寄列表
 */
const getBomlist = (page = 1, limit = 10, id = '') => {
  data.mailingData.bomData = [];
  const obj = {
    bomSerial: '',
    comments: '',
    customerAccountId: 0,
    description: '',
    designator: '',
    footprint: '',
    id: 0,
    layer: 0,
    limit: limit,
    manufacturer: '',
    manufacturerPn: '',
    minimumOrderQuantity: 0,
    minimunPackageQuantity: 0,
    name: '',
    page: page,
    pageType: 1,
    patchStatus: 0,
    pcbaOrderId: id,
    productId: 0,
    serial: '',
    smtOrderId: 0,
    source: 2,
    status: 0,
    supplier: '',
    supplierPn: '',
    supplyQuantity: 0,
  };
  getBomOrderDetail(obj).then((res) => {
    if (res.code === 200) {
      data.mailingData.bomData = res.data.list;
      data.mailingData.list = res.data;
    } else {
      ElMessage.error(res.msg);
    }
  });
  // queryPagePcbaSmtBomOrderExpressList(obj).then((res) => {
  //   if (res.code === 200) {
  //     data.mailingData.bomData = res.data.list;
  //     data.mailingData.list = res.data;
  //     console.log(res, 111);
  //   } else {
  //     ElMessage.error(res.msg);
  //   }
  // });
};

defineExpose({
  getBomlist,
});
onMounted(() => {
  // getBomlist();
});
</script>
